//
//  DownLoadCtl.m
//  afnleaks
//
//  Created by  Mac on 2021/3/31.
//

#import "DownLoadCtl.h"

@interface DownLoadCtl ()

@end

@implementation DownLoadCtl

- (void)viewDidLoad {
    [super viewDidLoad];
}


- (IBAction)downloadAction:(id)sender {
    //创建NSURLSessionConfiguration
        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
        
        //创建管理者对象
        AFURLSessionManager *manager = [[AFURLSessionManager alloc]initWithSessionConfiguration:configuration];
        
        //设置url
        NSURL *url = [NSURL URLWithString:@"http://127.0.0.1"];
        //创建请求对象
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        //文件路径
        NSURL *filePath = [NSURL fileURLWithPath:@"file://Users/Liu/Desktop/Note"];
        
        //上传任务
        NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithRequest:request fromFile:filePath progress:nil completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
            if(error){
                //错误
                NSLog(@"Error:%@",error);
            }else{
                //成功
                NSLog(@"Success %@ %@",response,responseObject);
            }
        }];
        //启动任务
        [uploadTask resume];
}

@end
